

function init(name, base) {
    CHAT_CLIENT.initialize(name, base);
    listener = new ChatClientListener();
    

    //Called when a new category is added, or a category is updated in system
    listener.onCategoryUpdated      = function(chatclient, categoryInfo) {       
        add(categoryInfo.id, categoryInfo.parentId, categoryInfo.name, "categor.html", 1);   
        write();
    };
    
    //Called when a category is removed from system
    listener.onCategoryRemoved      = function(chatclient, categoryId) {
        

    };

    //Called when a new room is added, or a room is updated in system
    listener.onRoomUpdated          = function(chatclient, roomInfo) {
        //TODO : buka room disini
        add(roomInfo.name , roomInfo.categoryId , "#" + roomInfo.name , "hoho.html");
        // CHAT_CLIENT.joinRoom(roomInfo.name);
        write();
    };

    //Called when a room is removed from system
    listener.onRoomRemoved          = function(chatclient, roomName) {
        removeTree(roomName);
        write();
    };

    //Called when a new friend is added, or a friend is updated in system
    listener.onFriendUpdated        = function(chatclient, userInfo) {
        //TODO : tampilkan friend di kolom ( * )
        document.getElementById('listFriend').innerHTML += "<span onclick=\"select('"+userInfo.username+"');\" class='namauser'>" + userInfo.username + " " +userInfo.isOnline + "</span><br>";

    };

    //Called when a friend is removed
    listener.onFriendRemoved        = function(chatclient, friendName) {

    };

    //Called when you successfully joined a room
    listener.onRoomJoined           = function(chatclient, roomInfo) {
        var out = "";
        for(asd in roomInfo.users) {
            if(roomInfo.users[asd].username == name) {
                out += "<span class='namauserself'>:) " + roomInfo.users[asd].username + "</span><br>";
            }
            else {
                out += ":] <span class='namauser'>" + roomInfo.users[asd].username + "</span><br>";
            }
        }
        document.getElementById('listuser').innerHTML = out;
        select("#"+roomInfo.name);
    };

    //Called when you successfully exited from a room
    listener.onRoomExited           = function(chatclient, roomName) {
        deleteTab(roomName);
        document.getElementById('label_#'+roomName).innerHTML   = "";
        document.getElementById('listuser').innerHTML           = "";
        write();
    };

    //Called when a private chat is sent to you
    listener.onPrivateChatUpdated   = function(chatclient, messageInfo) {
        if(messageInfo.senderName == name) {
            document.getElementById('label_'+messageInfo.window).innerHTML += "<span class='warnachat'>( " + messageInfo.senderName + " in " + messageInfo.time + " ) "+ messageInfo.content + "</span><br>";
        }
        else {
            select(messageInfo.window);
            document.getElementById('label_'+messageInfo.window).innerHTML += "( " + messageInfo.senderName + " in " + messageInfo.time + " ) "+ messageInfo.content + "<br>";
        }
        document.getElementById('centerin').scrollTop  = document.getElementById('label_'+messageInfo.window).offsetHeight;
    };

    //Called when an opened room is updated
    listener.onOpenedRoomUpdated    = function(chatclient, roomInfo) {
        for(asd in roomInfo.chats) {
            if(roomInfo.chats[asd].senderName == name) {
                document.getElementById('label_#'+roomInfo.name).innerHTML += "<span class='warnachat'>( " + roomInfo.chats[asd].senderName + " in " + roomInfo.chats[asd].time + " ) "+ roomInfo.chats[asd].content + "</span><br>";
            }
            else if(roomInfo.chats[asd].senderName == "System") {
                document.getElementById('label_#'+roomInfo.name).innerHTML += "<span class='warnachat'>( " + roomInfo.chats[asd].senderName + " in " + roomInfo.chats[asd].time + " ) "+ roomInfo.chats[asd].content + "</span><br>";
            }
            else {
                document.getElementById('label_#'+roomInfo.name).innerHTML += "( " + roomInfo.chats[asd].senderName + " in " + roomInfo.chats[asd].time + " ) "+ roomInfo.chats[asd].content + "<br>";
            }
            document.getElementById('centerin').scrollTop  = document.getElementById('label_#'+roomInfo.name).offsetHeight;   
        }
        var out = "";
        for(asd in roomInfo.users) {
            if(roomInfo.users[asd].username == name) {
                out += "<span class='namauserself'>:) " + roomInfo.users[asd].username + "</span><br>";
            }
            else {
                out += ":] <span class='namauser'>" + roomInfo.users[asd].username + "</span><br>";
            }
        }
        document.getElementById('listuser').innerHTML = out;
      
    };

    //Called when error occured (errorCode will be defined later)
    listener.onError                = function(chatclient, errorInfo) {
        alert(errorInfo.id + " > " + errorInfo.msg);
        alert(JSON.stringify(errorInfo));
    };

    CHAT_CLIENT.setListener(listener);
}   